<?php
namespace app\adminapi\controller\setting\lang;

use app\adminapi\controller\BaseAdminApiController;
use app\adminapi\lists\setting\lang\LangLists;
use app\adminapi\logic\setting\lang\LangLogic;
use app\adminapi\validate\setting\lang\LangValidate;

/**
 * 语言控制器
 * Class LanguasController
 * @package app\adminapi\controller\setting
 */
class LangController extends BaseAdminApiController
{
    public $notNeedLogin = ['getLangAll'];

    /**
     * 获取所有语言
     * @return \support\Response
     */
    public function getLangAll()
    {
        $result = LangLogic::getLangAll();
        return $this->data($result);
    }

    /**
     * @notes 获取语言列表
     * @return \support\Response
     */
    public function lists()
    {
        return $this->dataLists(new LangLists());
    }

    /**
     * @notes 查看语言详情
     * @return \support\Response
     */
    public function detail()
    {
        $params = (new LangValidate())->goCheck('detail');
        $result = LangLogic::detail($params);
        return $this->data($result);
    }

    /**
     * @notes 添加
     * @return \support\Response
     */
    public function add()
    {
        $params = (new LangValidate())->post()->goCheck('add');
        $result = LangLogic::add($params);
        if (true === $result) {
            return $this->success('添加成功', [], 1, 1);
        }
        return $this->fail(LangLogic::getError());
    }


    /**
     * @notes 编辑
     * @return \support\Response
     */
    public function edit()
    {
        $params = (new LangValidate())->post()->goCheck('edit');
        $result = LangLogic::edit($params);
        if (true === $result) {
            return $this->success('编辑成功', [], 1, 1);
        }
        return $this->fail(LangLogic::getError());
    }

    /**
     * @notes 切换默认语言
     * @return \support\Response
     */
    public function langChangeDefault()
    {
        $params = (new LangValidate())->post()->goCheck('changeDefault');
        $result = LangLogic::langChangeDefault($params);
        if (true === $result) {
            return $this->success('切换成功', [], 1, 1);
        }
        return $this->fail(LangLogic::getError());
    }

    /**
     * @notes 切换语言状态
     * @return \support\Response
     */
    public function langChangeStatus()
    {
        $params = (new LangValidate())->post()->goCheck('changeStatus');
        $result = LangLogic::langChangeStatus($params);
        if (true === $result) {
            return $this->success('切换成功', [], 1, 1);
        }
        return $this->fail(LangLogic::getError());
    }

    /**
     * @notes 删除
     * @return \support\Response
     */
    public function delete()
    {
        $params = (new LangValidate())->post()->goCheck('delete');
        $result = LangLogic::delete($params);
        if (true === $result) {
            return $this->success('删除成功', [], 1, 1);
        }
        return $this->fail(LangLogic::getError());
    }

}
